package com.da.javatest.niuke.jianzhi;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author chenlida
 * @date 2020/10/23 14:45
 * https://www.nowcoder.com/practice/390da4f7a00f44bea7c2f3d19491311b?
 * tpId=13&tags=&title=&diffculty=0&judgeStatus=0&rp=1
 */
public class C42Solution {
    public ArrayList<Integer> FindNumbersWithSum(int[] array, int sum) {
        ArrayList<Integer> list = new ArrayList<>();
        Arrays.sort(array);
        for (int i = 0; i < array.length; i++) {
            for (int j = array.length - 1; j > i; j--) {
                if (array[i] + array[j] == sum) {
                    list.add(array[i]);
                    list.add(array[j]);
                    return list;
                }
            }
        }
        return list;
    }
}
